﻿using System;
using System.Collections.Generic;
using System.Text;

namespace NFinal.Sql.Like
{
    /// <summary>
    /// 洗牌操作
    /// </summary>
    public class ShuffleCardUtil
    {

        public static int Encode(int n, int index)
        {
            int point = (n-1) >> 1;
            if (index > point)
            {
                return ((index - point - 1) << 1) + 1;
            }
            else
            {
                return (index << 1);
            }
        }

        public static int Decode(int n, int index)
        {
            int point = (n-1) >> 1;
            if ((index & 1) == 0)
            {
                return index >> 1;
            }
            else
            {
                return ((index - 1) >> 1) + point + 1;
            }
        }
    }
}
